<template>
<div class="wrap pd20">
  <div class="tip">{{$t('config.channel.forbiddenChatMessage')}}</div>
  <el-form label-position="top" ref="form" :model="form" class="form">
    <el-form-item :label="$t('config.channel.blackTips')">
      <el-input size="mini" v-model="form.blackTips" type="textarea" :placeholder="$t('config.channel.blackTipsPlaceholder')"></el-input>
    </el-form-item>
    <el-form-item :label="$t('config.channel.blackKeyword')" class="padding-top">
      <el-input size="mini" v-model.trim="form.blackKeyword" :placeholder="$t('config.channel.blackKeywordPlaceholder')"></el-input>
    </el-form-item>
    <el-form-item :label="$t('config.channel.applyReplyTips')" class="padding-top">
      <el-input size="mini" v-model="form.applyReplyTips" type="textarea" :placeholder="$t('config.channel.applyReplyTipsPlaceholder')"></el-input>
    </el-form-item>
    <el-form-item class="padding-top">
      <el-button type="primary" @click="submitForm" class="fr primary_btn">{{$t('config.channel.saveSettings')}}</el-button>
    </el-form-item>
  </el-form>
</div>
</template>
<script>
  export default {
    name: 'forbiddenChatCue',
    data () {
      return {
        flag: this.$store.getters.isEcommerce ? 'ecommerce' : 'kf',
        form: {
          blackTips: '',
          blackKeyword: '',
          applyReplyTips: ''
        },
        submitObj: {}
      }
    },
    components: {
    },
    computed: {
    },
    methods: {
      submitForm () {
        for (let i in this.form) {
          this.submitObj[i] = this.form[i]
        }
        let str = 'saveGlobalSet'
        if (this.flag === 'ecommerce') {
          str = 'saveECommerceGlobalSet'
        }
        this.$store.dispatch(str, this.submitObj).then((rep) => {
          if (rep.success) {
            this.$message.success(this.$t('config.channel.configSuccess'))
          } else {
            this.$message.error(this.$t('qualityCheck.saveFali'))
          }
        })
      }
    },
    beforeMount () {
      let str = 'getGlobalSetById'
      if (this.flag === 'ecommerce') {
        str = 'getECommerceGlobalSet'
      }
      this.$store.dispatch(str, {}).then((resp) => {
        if (resp.row) {
          this.submitObj = resp.row
          for (let i in this.form) {
            this.form[i] = this.submitObj[i]
          }
        }
      })
    }
  }
</script>
<style lang="stylus" scoped>
  @import "../../../../../assets/common.styl"
  .wrap
    padding 20px 16px
  .tip
    padding-bottom 15px
    color $c-prompt
  .padding-top
    padding-top 15px
  .form
    width 400px
</style>
